package com.henu.col05023.common;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.RowCallbackHandler;

import com.henu.col05023.common.bo.PassWord;
import com.henu.col05023.common.dao.BaseDAO;

public class TestConn extends BaseDAO {
	public void test() {
		System.out.println("test");
		List list = new ArrayList();
		for (int i = 5023001; i <= 5023227; i++) {
			list.clear();
			final String no = "0" + i;
			list.add(no);
			getJdbcTemplate().query(
					"select * from students_t where student_no=?",
					list.toArray(), new RowCallbackHandler() {
						public void processRow(ResultSet rs)
								throws SQLException {
							int count = rs.getMetaData().getColumnCount();
							for(int i=1;i<=count;i++){
								String value = rs.getString(i);
								String colname = rs.getMetaData().getColumnName(i);
								if(colname.equals("student_no") || colname.equals("student_name")
										|| colname.equals("sex") || colname.equals("company") || colname.equals("address")){
									continue;
								}
								StringBuffer sql = new StringBuffer();
								List<String> args = new ArrayList<String>();
								args.add(PassWord.encode(value));
								args.add(no);
								sql.append("update students_t set ").append(colname).append("=? where student_no=? ");
								getJdbcTemplate().update(sql.toString(),args.toArray());
							}
						}

					});

		}
		System.out.println("end");
	}

	public static void main(String[] args) throws Exception{

		Resource resource = new ClassPathResource("applicationContext.xml");
		BeanFactory factory = new XmlBeanFactory(resource);
		TestConn testConn = (TestConn) factory.getBean("testConn");
		testConn.test();

	}
}
